#include "ThreadManager.h"

ThreadManager::ThreadManager()
{

    m_threadA = new CThreadA(m_framework);
    m_threadB = new CThreadB(m_framework);
    m_threadA->setID(THREAD_A);
    m_threadB->setID(THREAD_B);
    setThreadID(THREAD_A, m_threadA->GetAddress());
    setThreadID(THREAD_B, m_threadB->GetAddress());

    int timeid1 = 100;
    int timeid0 = 20;
    m_timeid.push_back(timeid0);
    m_timeid.push_back(timeid1);
    m_threadA->setTimer(5000,TIME_ID_ONE);
    m_threadA->setTimer(1000,TIME_ID_TWO);

    m_num = 100;
    start();
}

void ThreadManager::start()
{
    //threadAͳźŸthreadB
    //m_threadA->send2ThreadbyID(0, THREAD_B);

}

void ThreadManager::stop()
{

}

int ThreadManager::setThreadID(int id, Theron::Address address)
{
    std::pair<std::map<int, Theron::Address>::iterator, bool> Insert_Res;
    Insert_Res = ID_ADDRESS_MAP.insert(std::pair<int, Theron::Address>(id, address));
    if (Insert_Res.second == true)
    {
        printf("Insert producer address to map successfully.\n");
        return 0;
    }

    printf("Insert producer address to map failed.\n");
    return -1;
}

